function errorMessageDiv() {
return document.getElementById("errorMessage");
}
function errorMessageHeader() {
return "Please correct the following and try again.<br>";
}
function setError(message, labelID) {
var errorMessageContainer = errorMessageDiv();
var msgDivID = labelID + "_error";
//if the header for the errors is not showing, show it
var currentContents = errorMessageContainer.innerHTML;
if (currentContents == "") {
errorMessageContainer.innerHTML = errorMessageHeader();
}
//if the message is supplied and is not being currently displayed, show it
if (document.getElementById(msgDivID) == null && message != "") {
errorMessageContainer.innerHTML = errorMessageContainer.innerHTML + "<div id='" + msgDivID + "'>--" + message + "</div>";
}
//set the error class for the label
var label = document.getElementById(labelID);
if (label != null) {
label.setAttribute("class", "errorClass");
}
}
function clearError(labelID) {
errorMessageContainer = errorMessageDiv();
//remove the error class from the item's label
var label = document.getElementById(labelID);
if (label != null) {
label.setAttribute("class", "");
}
//remove the specific error message
var toRemove = document.getElementById(labelID + "_error");
if (toRemove != null) {
errorMessageContainer.removeChild(toRemove);
}
var currentContents = errorMessageContainer.innerHTML;
var defaultMessage = errorMessageHeader();
//if the last error message was removed, then clear out the header
if (currentContents == defaultMessage) {
errorMessageContainer.innerHTML = "";
}
} 
function check(el,label,checkType,errorMessage,ASynch) {
    var getData = '?type=' + checkType + '&candidate=' + $(el).val();
    var returnValue = false;
    $.ajax({
        type: "POST",
        async: ASynch,
        url: '/checker' + getData,
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (msg) {
          returnValue = !!msg;
          if (returnValue == false) {
            setError(errorMessage, label);
          }
          else {
              clearError(label);
          }
        }
    });
    return returnValue;
}

